package com.share.two.f_mysql_jdbc.d_jdbcDaoSupport;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.stereotype.Service;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import com.share.two.f_mysql_jdbc.entity.User;


//@Service
public class UserDao extends JdbcDaoSupport{

	public void update(User user) {
		String sql = "update t_user set username=?,password=? where id =?";
		Object[] args = {user.getUsername(), user.getPassword(), user.getId()};
		this.getJdbcTemplate().update(sql, args);
	}

	public List<User> selectAll() {
		return this.getJdbcTemplate().query("select * from t_user", 
				ParameterizedBeanPropertyRowMapper.newInstance(User.class));
	}

}
